#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5005;

int n, m;
struct Rect {
  int x1, y1, x2, y2;
} rects[N];
struct Line {
  int l, r, h, op;
  bool operator<(const Line& o) const {
    if (h != o.h) return h < o.h;
    return op > o.op;
  }
} lines[N << 1];
int b[N << 1], num, n2;
int ans;

int sum[N << 3], tag[N << 3];
void build(int p, int l, int r) {
  if (l + 1 == r) {
    sum[p] = 0, tag[p] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid, r);
}
void pushup(int p, int l, int r) {
  if (tag[p])
    sum[p] = b[r] - b[l];
  else if (l + 1 == r)
    sum[p] = 0;
  else
    sum[p] = sum[p << 1] + sum[p << 1 | 1];
}
void addtag(int d, int p, int l, int r) {
  tag[p] += d;
  pushup(p, l, r);
}
void update(int L, int R, int d, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(d, p, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  if (L < mid) update(L, R, d, p << 1, l, mid);
  if (R > mid) update(L, R, d, p << 1 | 1, mid, r);
  pushup(p, l, r);
}
void solve() {
  sort(b + 1, b + n2 + 1);
  num = unique(b + 1, b + n2 + 1) - b - 1;
  rep(i, 1, n2) {
    lines[i].l = lower_bound(b + 1, b + num + 1, lines[i].l) - b;
    lines[i].r = lower_bound(b + 1, b + num + 1, lines[i].r) - b;
  }
  sort(lines + 1, lines + n2 + 1);
  build(1, 1, num);
  int pre = 0;
  rep(i, 1, n2) {
    update(lines[i].l, lines[i].r, lines[i].op, 1, 1, num);
    ans += abs(sum[1] - pre);
    pre = sum[1];
  }
}
void solve_x() {
  rep(i, 1, n) {
    b[i] = rects[i].x1, b[i + n] = rects[i].x2;
    lines[i] = {rects[i].x1, rects[i].x2, rects[i].y1, 1};
    lines[i + n] = {rects[i].x1, rects[i].x2, rects[i].y2, -1};
  }
  solve();
}
void solve_y() {
  rep(i, 1, n) {
    b[i] = rects[i].y1, b[i + n] = rects[i].y2;
    lines[i] = {rects[i].y1, rects[i].y2, rects[i].x1, 1};
    lines[i + n] = {rects[i].y1, rects[i].y2, rects[i].x2, -1};
  }
  solve();
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  n2 = n * 2;
  rep(i, 1, n) cin >> rects[i].x1 >> rects[i].y1 >> rects[i].x2 >> rects[i].y2;
  solve_x();
  solve_y();
  cout << ans;
  return 0;
}
